export default class ElementUtils{
  getElement(array, elementId){
    var foundElement = undefined;
    array.forEach(function (element) {
      if (typeof element.getId === 'function' && element.getId() === elementId) {
        foundElement = element;
      }
      if (element.id === elementId) {
        foundElement = element;
      }
    });
    return foundElement;
  }
  getElements(array, elementId){
    var foundElements = [];
    array.forEach(function(element) {
      if (typeof element.getId === 'function' && element.getId() === elementId) {
        foundElements.push(element);
      }
    });
    return foundElements;
  }
  removeElement(array, elementId){
    var isElementRemoved = false;
    array.forEach(function (element) {
      if (element.id === elementId) {
        var index = array.indexOf(element);
        if (index > -1) {
          array.splice(index, 1);
          isElementRemoved = true;
        }
      }
    });
    return isElementRemoved;
  }
  removeAllElements(array){
    array.length = 0;
  }
}
